package observers;

import java.util.ArrayList;
import java.util.List;

public class History {

	
	public History(String oped, String op, String operator)
	{
		history = new ArrayList<String>();
		this.oped = oped;
		this.op = op;
		this.operator = operator;
	}
	
	public final void print_history()
	{
		if (get_amount_recorded_operations() == 0)	print_empty_history();
		else					print_actual_history();

	}
	
	public void add_operation(int a, int b)
	{
		history.add(a + operator + b);
		integral_sum += a + b;
	}
	
	private final void print_empty_history()
	{
		System.out.println("No " + op + "s (" + operator + ") recorded");		
	}
	
	private final void print_actual_history()
	{
		System.out.println("Total of " + oped + " elements equals : " + get_integral_sum() );
		System.out.println("There were " + get_amount_recorded_operations() + " " + op + "s operations recorded:");
		int line = 0;
		for (String s : history)
		{
			System.out.println(" - Line " + line + " : " + s);
			line++;
		}
	}
	
	private final int get_amount_recorded_operations(){ return history.size();}

	private final int get_integral_sum() { return integral_sum;}
	
	private List<String> history;
	private int integral_sum;
	private final String oped;
	private final String op;
	private final String operator;
}

